using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FiltronASP.Logger;

namespace FiltronASP.Models.DAO.WIX
{
    public class WixInterchangeManufacturerDAO : Abstracts.AbstractGenericDAO<WixInterchangeManufacturer, System.Nullable<int>>,
        Interfaces.WIX.IWixInterchangeManufacturerDAO
    {
        /// <summary>
        /// Metoda zwracajaca nazwe parametru bedacego kluczem glownym tabeli.
        /// </summary>
        /// <returns>nazwa klucza glownego</returns>
        protected override string GetKeyProperty()
        {
            return "manufacturer_id";
        }

        /// <summary>
        /// Metoda zwracająca firmy produkującej filtr 'obcy'
        /// </summary>
        /// <param name="manufacturerId">id producenta</param>
        /// <returns>producent</returns>
        public IQueryable<WixInterchangeManufacturer> FindManufacturerById(int manufacturerId)
        {
            if (manufacturerId.Equals(0))
            {
                return null;
            }   //if
            try
            {
                IQueryable<WixInterchangeManufacturer> manufacturer = this._cmsEntitiesDataContext.WixInterchangeManufacturers.Where(
                    inma => inma.manufacturer_id.Equals(manufacturerId)
                        );
                if (!(manufacturer.Any()))
                {
                    return null;
                }   //if
                return manufacturer;
            }   //try
            catch (Exception ex)
            {
                MyLogger.Log(ex);
            }   //catch
            return null;
        }
    }
}